<?php

/**
 * SocialEngine
 *
 * @category   Application_Core
 * @package    Core
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 * @version    $Id: ListItems.php 7244 2010-09-01 01:49:53Z john $
 * @author     John
 */

/**
 * @category   Application_Core
 * @package    Core
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 */
class Socialengineaddon_Model_DbTable_Locations extends Engine_Db_Table {
	
	protected $_rowClass = 'Socialengineaddon_Model_Location';
	protected $_location;
	
	// Set the location
	public function setLocation($location = array()) {
		$select = $this->select ()->where ( 'location = ?', $location ['location'] );
		$row = $this->fetchRow ( $select );
		if ($row == null) {
			$row = $this->createRow ();
			$row->setFromArray ( $location );
		}
		if (null !== $row) {
			$row->setFromArray ( $location );
		}
		$row->save ();
		
		return $row->location_id;
	}
	// Get the location
	public function getLocation($location = array()) {
		$select = $this->select ();
		foreach ( $location as $key => $value ) {
			$select->where ( " $key = ?", $value );
		}
		return $this->fetchRow ( $select );
	}
	// Check the location
	public function hasLocation($location = array()) {
		$flage = 0;
		
		$result = $this->getLocation ( $location );
		if (! empty ( $result )) {
			$flage = 1;
		}
		
		return $flage;
	}
	// Delete the location
	public function clearLocation() {
		$result = $this->getLocation ( $location );
		if (! empty ( $result )) {
			$result->delete ();
		}
	
	}

}